#include "aky_program/aky_com_include.h"

#define AKY_UART_0_BUF_MAX 50  //串口最大接收个数
static uint8_t aky_uart_0_buf[AKY_UART_0_BUF_MAX];//串口缓存
static uint8_t aky_uart_0_buf_2[AKY_UART_0_BUF_MAX];//串口缓存
static uint16_t aky_uart_0_read_cnt = 0;//一帧数据结束串口接收到的数据个数
static uint8_t aky_uart_0_time_out = 0;//超时处理  超时则将处理一帧数据标志位置1
static uint8_t flag_aky_uart_0_get_data = 0;
static uint8_t flag_aky_task_0_decode = 0;//处理一帧数据标志位 置1代表接收到一帧数据
static uint8_t BLEUart0Data[20];
stru_aky_task_0_t Task0_BP;
uint8_t flag_aky_uart_0_judge = 0;//串口0同步标志位判断
static uint32_t u32_tick_last = 0;//超时处理  

static void aky_task_0_uart_decode(void);
static void aky_uart_0_init(void);
static void aky_uart_0_send_byte(uint8_t data);



void UART0_Handler(void)//uart_0 中断
{
	uint32_t chr;
	if(UART_INTStat(UART0, UART_IT_RX_THR))
	{
		while(UART_IsRXFIFOEmpty(UART0) == 0)
		{
        	if(UART_ReadByte(UART0, &chr) == 0)
        	{
                aky_uart_0_buf[aky_uart_0_read_cnt] = chr;
                aky_uart_0_read_cnt++;
                if (aky_uart_0_read_cnt > AKY_UART_0_BUF_MAX)//限制最大接收个数
                {
                    aky_uart_0_read_cnt = AKY_UART_0_BUF_MAX - 1;
                }
                aky_uart_0_time_out = 0;//超时时间清零
                u32_tick_last = g_u32_tick_cnt;
                flag_aky_uart_0_get_data = 1;
        	}
            else
            {
                __NOP();
            }
		}
	}
}



void Timer0Callback(void)//软件定时器 回调函数
{
    aky_uart_0_time_out++; //
    if (g_u32_tick_cnt - u32_tick_last > 30 / 10 && flag_aky_uart_0_get_data == 1)//超时着代表接收完一帧数据
    {
        u32_tick_last = g_u32_tick_cnt;
        flag_aky_uart_0_get_data = 0;
        flag_aky_task_0_decode = 1;//处理数据标志位置1
    }
    
}


static uint8_t *p_aky_uart_0_buf;
uint8_t MEM_FIRST_GAIN_VALUE_0 = 0;
uint8_t MEM_FIRST_GAIN_FLAGE_0 = 0;
static void aky_task_0_uart_decode(void)
{
    uint8_t k, Checksum, len;
    uint16_t index = 0;
    uint16_t read_cnt_temp = 0;

    if (flag_aky_task_0_decode == 1)
    {

        read_cnt_temp = aky_uart_0_read_cnt;
        memset(aky_uart_0_buf_2, 0, AKY_UART_0_BUF_MAX);
        memcpy(aky_uart_0_buf_2, aky_uart_0_buf, read_cnt_temp);
        aky_uart_0_read_cnt = 0;
        flag_aky_task_0_decode = 0;

        #if (AKY_PRINTF_TO_UART3 == 1)
        if (aky_uart_0_buf_2[3] != 0x51)
        {
            printf("rx0 decode\n");
            for (uint16_t i = 0; i < read_cnt_temp; i++)
            {
                printf(" %02x", aky_uart_0_buf_2[i]);
            }
            printf("\n");
        }
        #endif
        while (read_cnt_temp > 1)
        {
            read_cnt_temp--;
            p_aky_uart_0_buf = &aky_uart_0_buf_2[index];
            index++;
            if ((p_aky_uart_0_buf[0] == 0xA5) && (p_aky_uart_0_buf[1] == 0xA5))
            {
                len = p_aky_uart_0_buf[2];
                if (p_aky_uart_0_buf[len + 3] == 0x5A)
                {  
                    Checksum = 0;
                    for (k = 3; k < len + 2; k++)
                    {
                        Checksum += p_aky_uart_0_buf[k];
                    }
                    if (Checksum == p_aky_uart_0_buf[len + 2])
                    {
                        if (p_aky_uart_0_buf[3] == 0x9D)
                        {
                            printf("Fake you men!!!!!!\n");
                            aky_task_0_send_cmd(TASK0_BP_READY_Command);
							
                        }
                        if (p_aky_uart_0_buf[3] == 0x88)
                        {
                            Task0_BP.flag_reply = 1;
                        }

                        if (p_aky_uart_0_buf[3] == 0x57)
                        {
                            info_power_off();
                        }
                        if (p_aky_uart_0_buf[3] == 0xC9)
                        {
                            Task0_BP.e_aky_task_0_stat = TASK_0_STAT_PER_WAIT;
                        }
                        if (p_aky_uart_0_buf[3] == 0x5A)
                        {
                            Task0_BP.e_aky_task_0_stat = TASK_0_STAT_FAST_TEST;
                        }
                        if (p_aky_uart_0_buf[3] == 0xCA)
                        {
                            Task0_BP.step_code = p_aky_uart_0_buf[4];
                            #if 00
                            printf("cmd = 0xca step over step_code = %d step_code_last = %d\n",Task0_BP.step_code,Task0_BP.step_code_last);
                            #endif                            

                            if (Task0_BP.step_code_last != Task0_BP.step_code)
                            {
                                Task0_BP.step_code_last = Task0_BP.step_code;
                                Task0_BP.flag_step_end = 1;
                            }
                            

                        }                        
                        if (p_aky_uart_0_buf[3] == 0x51)
                        {
                            Task0_BP.transfer_voice = p_aky_uart_0_buf[4];
                            Task0_BP.transfer_uint = p_aky_uart_0_buf[5];
                            Task0_BP.transfer_year = p_aky_uart_0_buf[6];
                            Task0_BP.transfer_month = p_aky_uart_0_buf[7];
                            Task0_BP.transfer_day = p_aky_uart_0_buf[8];
                            Task0_BP.transfer_hour = p_aky_uart_0_buf[9];
                            Task0_BP.transfer_min = p_aky_uart_0_buf[10];
                            Task0_BP.transfer_secon = p_aky_uart_0_buf[11];

                            Task0_BP.s_get_time.year = Task0_BP.transfer_year;
                            Task0_BP.s_get_time.month = Task0_BP.transfer_month;
                            Task0_BP.s_get_time.day = Task0_BP.transfer_day;
                            Task0_BP.s_get_time.hour = Task0_BP.transfer_hour;
                            Task0_BP.s_get_time.min = Task0_BP.transfer_min;
                            Task0_BP.s_get_time.secon = Task0_BP.transfer_secon;
                            Task0_BP.flag_time_get_succ = 1;
                        }
                        if (p_aky_uart_0_buf[3] == 0x58)
                        {
                            Task0_BP.e_aky_task_0_stat = TASK_0_STAT_DOWN_CHANGE;
                        }
                        // if(Task0_BP.e_aky_task_0_stat == TASK_0_STAT_FREE)
                        {
                            if (p_aky_uart_0_buf[3] == 0xC1)
                            {
                                Task0_BP.e_aky_task_0_stat = TASK_0_STAT_ZERO;
                                // flag_aky_uart_0_judge = 1;
    
                            }
                            
                        }
                        // if(Task0_BP.e_aky_task_0_stat == TASK_0_STAT_ZERO)
                        {
                            if (p_aky_uart_0_buf[3] == 0xC2)
                            {
                                Task0_BP.e_aky_task_0_stat = TASK_0_STAT_TESTING;
						    	// flag_aky_uart_0_judge = 2;
                            }
                            
                        }
                        // if(Task0_BP.e_aky_task_0_stat == TASK_0_STAT_TESTING)
                        {
                            if (p_aky_uart_0_buf[3] == 0xC3)
                            {
                                Task0_BP.pres_mmg = p_aky_uart_0_buf[4] << 8 | p_aky_uart_0_buf[5];
                            }
                            if (p_aky_uart_0_buf[3] == 0xC4)
                            {
                                Task0_BP.result = p_aky_uart_0_buf[4];
                                Task0_BP.pres_sys = p_aky_uart_0_buf[5];
                                Task0_BP.pres_dia = p_aky_uart_0_buf[6];
                                Task0_BP.pulse = p_aky_uart_0_buf[7];
                                Task0_BP.PAD = p_aky_uart_0_buf[8];

                                if (Task0_BP.result == 1)
                                {
                                    Task0_BP.e_aky_task_0_stat = TASK_0_STAT_TEST_SUCC;
                                }
                                else if(Task0_BP.result == 0)
                                {
                                    Task0_BP.e_aky_task_0_stat = TASK_0_STAT_TEST_FAIL;
                                    Task0_BP.ERRORCode = p_aky_uart_0_buf[5];

                                }
                            }
                        }
                        // if(Task0_BP.e_aky_task_0_stat == TASK_0_STAT_TEST_SUCC || Task0_BP.e_aky_task_0_stat == TASK_0_STAT_TEST_FAIL)
                        {
                            if (p_aky_uart_0_buf[3] == 0xCF)
                            {
                                Task0_BP.e_aky_task_0_stat = TASK_0_STAT_FREE;
                            }
                        }
                        // if(Task0_BP.e_aky_task_0_stat == TASK_0_STAT_PER_READY )
                        {
                            if (p_aky_uart_0_buf[3] == 0xC5)
                            {
                                Task0_BP.PER_Alltime = (p_aky_uart_0_buf[4] * 60);
                                // Task0_BP.PER_Steptime = p_aky_uart_0_buf[5];
                            }
                            if (p_aky_uart_0_buf[3] == 0xC6)
                            {
                                Task0_BP.e_aky_task_0_stat = TASK_0_STAT_PER_WAIT;
                            }
                        }
                        // if(Task0_BP.e_aky_task_0_stat == TASK_0_STAT_PER_ING)
                        {
                            if (p_aky_uart_0_buf[3] == 0xC7)
                            {
                                Task0_BP.pres_mmg = p_aky_uart_0_buf[4] << 8 | p_aky_uart_0_buf[5];
                                Task0_BP.PER_Steptime = (p_aky_uart_0_buf[6] * 60) + p_aky_uart_0_buf[7];
                                Task0_BP.PER_Alltime = (p_aky_uart_0_buf[8] * 60) + p_aky_uart_0_buf[9];
                                Task0_BP.PER_PumpStatus = p_aky_uart_0_buf[10];
                            }
                            else if (p_aky_uart_0_buf[3] == 0xC8)
                            {
                                Task0_BP.ERRORCode = p_aky_uart_0_buf[4];
                                Task0_BP.e_aky_task_0_stat = TASK_0_STAT_PER_FAIL;
                            }
                            else if (p_aky_uart_0_buf[3] == 0xC9)
                            {
                                Task0_BP.e_aky_task_0_stat = TASK_0_STAT_PER_WAIT;
                            }
                        }

                        // if(Task0_BP.e_aky_task_0_stat == TASK_0_STAT_MEM_GAIN)
                        {
                            if (p_aky_uart_0_buf[3] == 0xD1)
                            {
                                Task0_BP.MEM_INDEX = p_aky_uart_0_buf[4];
                                Task0_BP.MEM_pres_sys = p_aky_uart_0_buf[5];
                                Task0_BP.MEM_pres_dia = p_aky_uart_0_buf[6];
                                Task0_BP.MEM_pulse = p_aky_uart_0_buf[7];
                                Task0_BP.MEM_PAD = p_aky_uart_0_buf[8];
                                Task0_BP.Mem_year = p_aky_uart_0_buf[9];
                                Task0_BP.Mem_month = p_aky_uart_0_buf[10];
                                Task0_BP.Mem_day = p_aky_uart_0_buf[11];
                                Task0_BP.Mem_hour = p_aky_uart_0_buf[12];
                                Task0_BP.Mem_min = p_aky_uart_0_buf[13];
                                Task0_BP.Mem_secon = p_aky_uart_0_buf[14];

                                if(MEM_FIRST_GAIN_FLAGE_0 == 1)
                                {
                                    MEM_FIRST_GAIN_FLAGE_0 = 0;
                                    MEM_FIRST_GAIN_VALUE_0 = Task0_BP.MEM_INDEX;
                                }
                                
                                if(MEM_FIRST_GAIN_VALUE_0 == 0)
                                {
                                    Task0_BP.e_aky_task_0_stat = TASK_0_STAT_MEM_GAIN_OVER;
                                }
                                else if(MEM_FIRST_GAIN_VALUE_0 != 0)
                                {
                                    MEM_FIRST_GAIN_VALUE_0--;
                                    aky_task_0_send_cmd(TASK0_MEM_GAIN_Command);
                                }

                            }
                        }
                        // if(Task0_BP.e_aky_task_0_stat == TASK_0_STAT_MEM_DELEAT)
                        {
                            if (p_aky_uart_0_buf[3] == 0xD3)
                            {
                                Task0_BP.e_aky_task_0_stat = TASK_0_STAT_MEM_DELEAT_OVER;
                            }
                        }
                        // if(Task0_BP.e_aky_task_0_stat == TASK_0_STAT_C || Task0_BP.e_aky_task_0_stat == TASK_0_STAT_CAL)
                        {
                            if (p_aky_uart_0_buf[3] == 0x53)
                            {
                                Task0_BP.version_mon = p_aky_uart_0_buf[4];
                                Task0_BP.version_date = p_aky_uart_0_buf[5];
                            }
                            if(p_aky_uart_0_buf[3] == 0x54)
                            {
                                Task0_BP.pres_mmg = p_aky_uart_0_buf[4] << 8 | p_aky_uart_0_buf[5];
                                Task0_BP.flag_get_engi_pres_cmd = 1;
                            }
                            if(p_aky_uart_0_buf[3] == 0x55)
                            {
                                Task0_BP.Lefttestnumber = p_aky_uart_0_buf[4] << 8 | p_aky_uart_0_buf[5];
                                Task0_BP.e_aky_task_0_stat = TASK_0_STAT_LIFETEST;
                            }
                            if(p_aky_uart_0_buf[3] == 0x56)
                            {
                                Task0_BP.cal_succ_code = p_aky_uart_0_buf[4];
                                if (Task0_BP.cal_succ_code == 1)
                                {
                                    Task0_BP.e_aky_task_0_stat = TASK_0_STAT_CAL_SUCC;
                                }
                                else
                                {
                                    Task0_BP.e_aky_task_0_stat = TASK_0_STAT_CAL_ERR;
                                }
                            }
                        }
                        // if(Task0_BP.e_aky_task_0_stat == TASK_0_STAT_LIFETEST)
                        {
                            if(p_aky_uart_0_buf[3] == 0x55)
                            {
                                Task0_BP.Lefttestnumber = p_aky_uart_0_buf[4] << 8 | p_aky_uart_0_buf[5];
                            }
                        }
                        // if(Task0_BP.e_aky_task_0_stat == TASK_0_STAT_WRITE_MEM)
                        {
                            if(p_aky_uart_0_buf[3] == 0x52)
                            {
                                Task0_BP.WriteMem_time = p_aky_uart_0_buf[4];
                                Task0_BP.WriteMem_ok = p_aky_uart_0_buf[5];
                            }
                        }

                    }
                }
            }
        }
        
        aky_uart_0_read_cnt = 0;
        flag_aky_task_0_decode = 0;
    }
    //
}
void clr_task_0_data(void)
{
    memset(&Task0_BP,0x00,sizeof(stru_aky_task_0_t));
}
void aky_task_0_send_cmd(e_aky_Mcu_task0contrl cmd)
{
    uint8_t data0len;
    BLEUart0Data[0] = 0xA5;
    BLEUart0Data[1] = 0xA5;
    if (cmd == TASK0_BP_READY_Command)
    {
        data0len = 2;
        BLEUart0Data[2] = data0len;
        BLEUart0Data[3] = TASK0_BP_READY_Command;
    }
    if (cmd == TASK0_BP_START_Command)
    {
        data0len = 2;
        BLEUart0Data[2] = data0len;
        BLEUart0Data[3] = TASK0_BP_START_Command;
    }
    if (cmd == TASK0_BP_STOP_Command)   //退出血压模式或者预适应模式
    {
        data0len = 2;
        BLEUart0Data[2] = data0len;
        BLEUart0Data[3] = TASK0_BP_STOP_Command;
        Task0_BP.e_aky_task_0_stat = TASK_0_STAT_FREE;
        clr_task_0_data();
    }
    if (cmd == TASK0_PER_PREPARE_Command)
    {
        data0len = 6;
        BLEUart0Data[2] = data0len;
        BLEUart0Data[3] = TASK0_PER_PREPARE_Command;
        BLEUart0Data[4] = Task0_BP.PER_Mode;
        BLEUart0Data[5] = Task0_BP.pre_hold_time;
        BLEUart0Data[6] = (Task0_BP.pre_keep_pres & 0xff00) >> 8;
        BLEUart0Data[7] = Task0_BP.pre_keep_pres & 0x00ff;
    }
    if (cmd == TASK0_PER_UP)
    {
        data0len = 4;
        BLEUart0Data[2] = data0len;
        BLEUart0Data[3] = TASK0_PER_UP;
        BLEUart0Data[4] = (Task0_BP.pre_set & 0xff00) >> 8;
        BLEUart0Data[5] = Task0_BP.pre_set & 0x00ff;
    }
    if (cmd == TASK0_PER_DOWN)
    {
        data0len = 4;
        BLEUart0Data[2] = data0len;
        BLEUart0Data[3] = TASK0_PER_DOWN;
        BLEUart0Data[4] = (Task0_BP.pre_set & 0xff00) >> 8;
        BLEUart0Data[5] = Task0_BP.pre_set & 0x00ff;
    }
    if (cmd == TASK0_TIME_ADJUST)
    {
        data0len = 3;
        BLEUart0Data[2] = data0len;
        BLEUart0Data[3] = TASK0_TIME_ADJUST;
        BLEUart0Data[4] = Task0_BP.pre_hold_time;
    }
    if (cmd == TASK0_PER_START_Command)
    {
        data0len = 2;
        BLEUart0Data[2] = data0len;
        BLEUart0Data[3] = TASK0_PER_START_Command;
        Task0_BP.e_aky_task_0_stat = TASK_0_STAT_PER_ING;
    }
    if (cmd == TASK0_MEM_GAIN_Command)
    {
        data0len = 2;
        BLEUart0Data[2] = data0len;
        BLEUart0Data[3] = TASK0_MEM_GAIN_Command;
        Task0_BP.e_aky_task_0_stat = TASK_0_STAT_MEM_GAIN;
        MEM_FIRST_GAIN_FLAGE_0 = 1;
        MEM_FIRST_GAIN_VALUE_0 = 0;
    }
    if (cmd == TASK0_MEM_DELEAT_Command)
    {
        data0len = 2;
        BLEUart0Data[2] = data0len;
        BLEUart0Data[3] = TASK0_MEM_DELEAT_Command;
        Task0_BP.e_aky_task_0_stat = TASK_0_STAT_MEM_DELEAT;
    }
    if (cmd == TASK0_BP_DOWN_Command)
    {
        data0len = 2;
        BLEUart0Data[2] = data0len;
        BLEUart0Data[3] = TASK0_BP_DOWN_Command;
        Task0_BP.e_aky_task_0_stat = TASK_0_STAT_STOPMODE;
    }
    if (cmd == TASK0_C_Command)
    {
        data0len = 2;
        BLEUart0Data[2] = data0len;
        BLEUart0Data[3] = TASK0_C_Command;
        Task0_BP.e_aky_task_0_stat = TASK_0_STAT_C;
    }
    if (cmd == TASK0_CAL_Command)
    {
        data0len = 2;
        BLEUart0Data[2] = data0len;
        BLEUart0Data[3] = TASK0_CAL_Command;
        Task0_BP.e_aky_task_0_stat = TASK_0_STAT_CAL;
    }
    if (cmd == TASK0_BP_CALOK_Command)
    {
        data0len = 2;
        BLEUart0Data[2] = data0len;
        BLEUart0Data[3] = TASK0_BP_CALOK_Command;
    }
    if (cmd == TASK0_LifeTest_Command)
    {
        data0len = 2;
        BLEUart0Data[2] = data0len;
        BLEUart0Data[3] = TASK0_LifeTest_Command;
    }
    if (cmd == TASK0_MEM_WRITE_Command)
    {
        data0len = 2;
        BLEUart0Data[2] = data0len;
        BLEUart0Data[3] = TASK0_MEM_WRITE_Command;
    }
    if (cmd == TASK0_4G_TIME_Command)
    {
        data0len = 2;
        BLEUart0Data[2] = data0len;
        BLEUart0Data[3] = TASK0_4G_TIME_Command;
    }
    if (cmd == TASK0_get_TIME_Command)
    {
        data0len = 2;
        BLEUart0Data[2] = data0len;
        BLEUart0Data[3] = TASK0_get_TIME_Command;
    }
    if (cmd == TASK0_ENTER_EMC)
    {
        data0len = 2;
        BLEUart0Data[2] = data0len;
        BLEUart0Data[3] = TASK0_ENTER_EMC;
    }
    if (cmd == TASK0_CHARGE_POWER_ON)
    {
        data0len = 2;
        BLEUart0Data[2] = data0len;
        BLEUart0Data[3] = TASK0_CHARGE_POWER_ON;
    }
    if (cmd == TASK0_FAST_TEST_MODE)
    {
        data0len = 2;
        BLEUart0Data[2] = data0len;
        BLEUart0Data[3] = TASK0_FAST_TEST_MODE;
    }
    
    BLEUart0Data[data0len + 2] = Cal_CRC0(data0len);
    BLEUart0Data[data0len + 3] = 0x5A; 
    BLEUart0Data[data0len + 4] = 0x5A;

    Send_BLe_data0(data0len + 5);
}

uint8_t Cal_CRC0(uint8_t len)
{
    uint8_t chensum, i;
    chensum = 0;
    for (i = 3; i < len + 2; i++)
    {
        chensum += BLEUart0Data[i];
    }
    return chensum;
}

void Send_BLe_data0(uint8_t secdlen)
{
    uint8_t i;
    #if (AKY_PRINTF_TO_UART3 == 1)
    if (BLEUart0Data[3] == TASK0_get_TIME_Command)
    {
        for (i = 0; i < secdlen; i++)
        {
            aky_uart_0_send_byte(BLEUart0Data[i]);
        }
    }
    else
    {
        printf("tx0 Send\n");
        for (i = 0; i < secdlen; i++)
        {
            aky_uart_0_send_byte(BLEUart0Data[i]);
            printf("%02x ", BLEUart0Data[i]);
        }
        printf("\n");
    }

    #else
    for (i = 0; i < secdlen; i++)
    {
        aky_uart_0_send_byte(BLEUart0Data[i]);
    }
    #endif
}


void aky_task_0(void) // 任务入口
{
    Timer0Callback();
    aky_task_0_uart_decode();
    /*此处后续添加未接收到回复值重发机制*/
}


static void aky_uart_0_init(void)
{
    UART_InitStructure UART_initStruct;
    GPIO_Init(GPIOM, PIN0, 0, 1, 0, 0);

    PORT_Init(PORTM, PIN1, PORTM_PIN1_UART0_TX, 0); //GPIOM.1配置为UART0输出引脚
    PORT_Init(PORTM, PIN0, PORTM_PIN0_UART0_RX, 1); //GPIOM.0配置为UART0输入引脚
    
    UART_initStruct.Baudrate = 115200;//波特率
    UART_initStruct.DataBits = UART_DATA_8BIT;
    UART_initStruct.Parity = UART_PARITY_NONE;
    UART_initStruct.StopBits = UART_STOP_1BIT;
    UART_initStruct.RXThreshold = 0;
    UART_initStruct.RXThresholdIEn = 1;
    UART_initStruct.TXThreshold = 3;
    UART_initStruct.TXThresholdIEn = 0;
    UART_initStruct.TimeoutTime = 10;
    UART_initStruct.TimeoutIEn = 0;
    UART_Init(UART0, &UART_initStruct);
    UART_Open(UART0);
}

// 发送一个字节
static void aky_uart_0_send_byte(uint8_t data)
{
    uint32_t time_out = 0;
    UART_WriteByte(UART0, data);
    while (UART_IsTXBusy(UART0))
    {
        time_out++;
        __NOP();
        if (time_out > 666666)
        {
            break;
        }
    }
}




void aky_task_0_init(void)
{
    aky_uart_0_init();
}

void send_time_syn(s_time_t s_time)
{
    uint8_t send_buf[20];
    uint16_t send_len;
    uint8_t check_sum = 0;
    uint16_t i;
    send_len = 10;

    send_buf[0] = 0xA5;
    send_buf[1] = 0xA5;
    send_buf[2] = send_len;
    send_buf[3] = 0xf6;
    send_buf[4] = 0x01;
    send_buf[5] = 0x01;

    send_buf[6] = s_time.year;
    send_buf[7] = s_time.month;
    send_buf[8] = s_time.day;
    send_buf[9] = s_time.hour;
    send_buf[10] = s_time.min;
    send_buf[11] = s_time.secon;
    
    for (i = 3; i < send_len + 2; i++)
    {
        check_sum += send_buf[i];
    }
    
    send_buf[send_len + 2] = check_sum;
    send_buf[send_len + 3] = 0x5A; 
    send_buf[send_len + 4] = 0x5A;
printf("send_time_syn\n");
    for (i = 0; i < send_len + 5; i++)
    {
        aky_uart_0_send_byte(send_buf[i]);
        printf("%02x ", send_buf[i]);
    }
printf("\n");

}

void clr_get_time_flag(void)
{
    Task0_BP.flag_time_get_succ = 0;
}
